package com.nbstar.film.spider.excel;

import com.nbstar.film.spider.domain.FilmSpiderDomain;
import com.nbstar.film.spider.pojo.RawFromExcel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFRow;

import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

@Data
@Slf4j
public class CommonExcelReader extends XSSFExcelReader {

    private int colIndex = 0;
    private int colImdbURLIndex = 0;
    private String spider = FilmSpiderDomain.SPIDER_FROM_MAOYAN;
    private boolean readSeqNo = false;
    private boolean readCoyright = false;
    private int     seqNoIdex = 0;
    private int     copyrightNum = 0;

    public CommonExcelReader(int colIndex) {
        this.colIndex = colIndex;
    }



    public CommonExcelReader() {
    }

    @Override
    public RawFromExcel readRowFromExcel(XSSFRow row) {
        RawFromExcel  rawFromExcel = new RawFromExcel();
        String fileName = (String) getCellValue(row, colIndex);

        rawFromExcel.setFilmName(fileName);
        if (readSeqNo) {
            rawFromExcel.setSeqNo((int) Double.parseDouble(getCellValue(row, seqNoIdex)));
        }

        if (readCoyright) {
            rawFromExcel.setCopyrightNumber(getCellValue(row, copyrightNum));
        }

        if (spider.equals(FilmSpiderDomain.SPIDER_FROM_IMDB)) {
            rawFromExcel.setImdbUrl(getCellValue(row, colImdbURLIndex));
        }

        return rawFromExcel;
    }
}

